//
//  HGNormalAvatorCollectionViewCell.m
//  悦享
//
//  Created by dllo on 16/3/19.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HGNormalAvatorCollectionViewCell.h"
#import "HGSubNORmalAvrolCollectionViewCell.h"
@interface HGNormalAvatorCollectionViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, retain) UICollectionView *collection;

@end

@implementation HGNormalAvatorCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self craeteCollection];
    }
    return self;
}

- (void)setArr:(NSMutableArray *)arr{
    _arr = arr;
    [_collection reloadData];
}

- (void)craeteCollection{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 5;
    layout.minimumLineSpacing = 50;
    layout.sectionInset = UIEdgeInsetsMake( 10, 10, 10, 10);
    
    layout.itemSize = CGSizeMake((self.frame.size.width - 170)/4, 70);
    
    self.collection = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collection];
    
    [_collection registerClass:[HGSubNORmalAvrolCollectionViewCell class] forCellWithReuseIdentifier:@"HGSubNORmalAvrolCollectionViewCell"];
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HGSubNORmalAvrolCollectionViewCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HGSubNORmalAvrolCollectionViewCell" forIndexPath:indexPath];
    TVModel *model = _arr[indexPath.row];
    
    Cell.model = model;
   
    return Cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    TVModel *model = _arr[indexPath.row];
    
    [self.delegate jumpAVtoWebVcWithUrl:model.playUrl];
    
}

@end
